﻿
/**
 * 当前：余额兑换物品
 * 其中：
 * 0 表示需要消耗的余额
 * 1 表示兑换的物品id
 * 2 表示兑换到的物品数量
 */
var selArr = [];
var selType;
var 赞助余额;
var nxnum = 0;
var goldnum = 0;
var pgldnum = 0;
var selitem;
var itemArr = [ //道具
    [30, 1662002, 1],
	[100, 4310019, 10],
    [30, 1662003, 1],
    [2, 1672000, 1],
    [5, 1672006, 1],
    [10, 1672001, 1],
    [20, 1672002, 1],
    [30, 1672003, 1],
    [40, 1672004, 1],
    [50, 1672005, 1],
    //[100, 4001326, 1],
   // [100, 4001328, 1],
	[60, 5570000, 100],
	[100, 4031344, 100],
    [10, 4003001, 100],
    [30, 4011004, 40],
    [30, 4011009, 40],
    [30, 4021004, 40],
    [30, 4011005, 40],
    [30, 4021001, 40],
    [30, 4011001, 40],
    [30, 4021005, 40],
    [30, 4011000, 40],
    [30, 4011003, 40],
    [30, 4005002, 40],
    [30, 4011002, 40],
    [30, 4021003, 40],
    [30, 4011006, 40],
    [30, 4021006, 40],
    [30, 4021002, 40],
    [30, 4021007, 40],
    [30, 4005000, 40],
    [30, 4021000, 40],
    [100, 4005004, 40],
    [100, 4021008, 40],
    [120, 4005001, 40],
    [120, 4005003, 40],
    [120, 4011008, 40]
    
    
]
var equipArr = [ //装备
    [2, 1003225, 1],
    [2, 1012260, 1],
    [2, 1022118, 1],
    [5, 1112596, 1],
    [5, 1132086, 1],
    [5, 1152050, 1],
    [5, 1122105, 1],
    [5, 1002850, 1],
    [5, 1082149, 1],
    [5, 1102041, 1],
    [5, 1072239, 1],
    [5, 1012058, 1],
    [10, 1003552, 1],
    [10, 1052461, 1],
    [10, 1072666, 1],
    [10, 1082433, 1],
    [10, 1102441, 1],
    [10, 1113036, 1],
    [10, 1132154, 1],
    [10, 1152089, 1],
    [20, 1004172, 1],
    [20, 1012471, 1],
    [20, 1052758, 1],
    [20, 1102691, 1],
    [20, 1122280, 1],
    [20, 1142724, 1],
    [30, 1004492, 1],
    [30, 1052929, 1],
    [20, 1073057, 1],
    [30, 1082647, 1],
    [30, 1098008, 1],
    [30, 1099014, 1],
    [30, 1102828, 1],
    [30, 1122306, 1],
    [30, 1132287, 1],
    [30, 1142833, 1],
    [30, 1152187, 1],
    [30, 1012524, 1],
    [50, 1113063, 1],
    [50, 1113064, 1],
    [50, 1113065, 1],
    [50, 1113066, 1],
    [50, 1113072, 1],
    [50, 1122264, 1],
    [50, 1132243, 1],
    [50, 1032220, 1],
    [80, 1113073, 1],
    [80, 1122265, 1],
    [80, 1132244, 1],
    [80, 1032221, 1],
    [100, 1113074, 1],
    [100, 1122266, 1],
    [100, 1132245, 1],
    [100, 1032222, 1],
    [200, 1113075, 1],
    [200, 1122267, 1],
    [200, 1132246, 1],
    [200, 1032223, 1],
    [300, 1132178, 1],
    [300, 1132177, 1],
    [300, 1132176, 1],
    [300, 1132175, 1],
    [300, 1132174, 1],
    [300, 1102485, 1],
    [300, 1102484, 1],
    [300, 1102483, 1],
    [300, 1102482, 1],
    [300, 1102481, 1],
    [300, 1082547, 1],
    [300, 1082546, 1],
    [300, 1082545, 1],
    [300, 1082544, 1],
    [300, 1082543, 1],
    [300, 1072747, 1],
    [300, 1072746, 1],
    [300, 1072745, 1],
    [300, 1072744, 1],
    [300, 1072743, 1],
    [300, 1003797, 1],
    [300, 1003800, 1],
    [300, 1003798, 1],
    [300, 1003799, 1],
    [300, 1003801, 1],
    [300, 1062167, 1],
    [300, 1062165, 1],
    [300, 1062169, 1],
    [300, 1062166, 1],
    [300, 1062168, 1],
    [300, 1042257, 1],
    [300, 1042255, 1],
    [300, 1042254, 1],
    [300, 1042256, 1],
    [300, 1042258, 1],
    [300, 1152179, 1],
    [300, 1152178, 1],
    [300, 1152177, 1],
    [300, 1152176, 1],
    [300, 1152174, 1],
    [300, 1102797, 1],
    [300, 1102796, 1],
    [300, 1102795, 1],
    [300, 1102794, 1],
    [300, 1102775, 1],
    [300, 1082640, 1],
    [300, 1082639, 1],
    [300, 1082638, 1],
    [300, 1082637, 1],
    [300, 1082636, 1],
    [300, 1073035, 1],
    [300, 1073034, 1],
    [300, 1073033, 1],
    [300, 1073032, 1],
    [300, 1073030, 1],
    [300, 1052890, 1],
    [300, 1052889, 1],
    [300, 1052888, 1],
    [300, 1052887, 1],
    [300, 1052882, 1],
    [300, 1004426, 1],
    [300, 1004425, 1],
    [300, 1004424, 1],
    [300, 1004423, 1],
    [300, 1004422, 1]
]
var cashArr = [ //时装
    [200, 5000212, 1],
    [20, 1004042, 1],
    [20, 1004044, 1],
    [30, 1049002, 1],
    [30, 1049003, 1],
    [30, 1049004, 1],
    [80, 1052579, 1],
    [60, 1072782, 1],
    [20, 1113021, 1],
    [50, 1082553, 1],
    [60, 1082505, 1],
    [50, 1032234, 1],
    [30, 1102653, 1],
    [40, 1102659, 1],
    [30, 1102555, 1]
]
var ConsumArr = [//消耗品
    [1, 2430227, 10],
    [5, 2049130, 1],
    [10, 2049131, 1],
    [20, 2049132, 1],
    [5, 2060004, 1],
    [5, 2061004, 1],
    [10, 2060011, 1],
    [10, 2061009, 1],
    [5, 2330003, 1],
    [5, 2330004, 1],
    [10, 2330005, 1],
    [10, 2330007, 1],
    [5, 2070001, 1],
    [5, 2070002, 1],
    [5, 2070003, 1],
    [5, 2070004, 1],
    [5, 2070005, 1],
    [5, 2070008, 1],
    [5, 2070009, 1],
    [5, 2070010, 1],
    [5, 2070011, 1],
    [5, 2070012, 1],
    [5, 2070013, 1],
    [10, 2070006, 1],
    [10, 2070007, 1],
    [30, 2070019, 1],
    [10, 2003509, 20],
    [10, 2003515, 20],
  //  [10, 2430227, 20],
    [10, 2003517, 10],
    [10, 2003519, 10],
    [10, 2210005, 10],
    [10, 2210011, 10],
    [10, 2210015, 10],
    [10, 2210019, 10],
    [10, 2210020, 10],
    [10, 2210021, 10],
    [10, 2210022, 10],
    [10, 2210061, 10],
    [10, 2210068, 10],
    [10, 2211000, 10],
    [10, 2212000, 10],
    [10, 2213000, 10],
    [10, 2213002, 10],
    [10, 2213003, 10],
    [10, 2213004, 10],
    [10, 2213005, 10],
    [10, 2213006, 10],
    [10, 2213007, 10],
    [10, 2213008, 10],
    [10, 2213009, 10],
    [10, 2213010, 10],
    [10, 2213011, 10],
    [10, 2213012, 10],
    [10, 2213013, 10],
    [10, 2213014, 10],
    [10, 2213015, 10],
    [10, 2213016, 10],
    [10, 2213017, 10],
    [10, 2213018, 10],
    [10, 2213019, 10],
    [10, 2213020, 10],
    [10, 2213021, 10],
    [10, 2213022, 10],
    [10, 2213023, 10],
    [10, 2213024, 10],
    [10, 2213025, 10],
    [10, 2213026, 10],
    [10, 2213027, 10],
    [10, 2213028, 10],
    [10, 2213029, 10],
    [10, 2213030, 10],
    [10, 2213031, 10],
    [10, 2213032, 10],
    [10, 2213036, 10],
    [10, 2213037, 10],
    [10, 2213038, 10],
    [10, 2213039, 10],
    [10, 2213040, 10],
    [10, 2213041, 10],
    [10, 2213042, 10]
];
var SettingsArr = [//设置栏
    [10, 3010835, 1],
    [10, 3015002, 1],
    [10, 3015014, 1],
    [10, 3015111, 1],
    [10, 3015075, 1],
    [10, 3015181, 1],
    [10, 3015262, 1],
    [10, 3015276, 1],
    [10, 3015310, 1],
    [10, 3015325, 1],
    [10, 3015326, 1],
    [10, 3015327, 1],
    [10, 3016000, 1],
    [10, 3015565, 1],
    [10, 3015567, 1],
    [10, 3015568, 1],
    [10, 3015570, 1],
    [10, 3015571, 1],
    [10, 3015572, 1],
    [10, 3010151, 1],
    [10, 3010108, 1],
    [10, 3010073, 1],
    [10, 3010070, 1],
    [10, 3010044, 1],
    [10, 3010077, 1],
    [10, 3012003, 1]
];
var status = 0;
var rn = "\r\n\r\n"; // 换行

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0) {           
            cm.dispose();
			cm.openNpc(9900004);
            return;
        }
        if (mode == 1) {
            status++;
        } else {
            status--;
        }
        if (status === 0) {
            赞助余额 = cm.getBossRank("赞助余额", 2) == -1 ? 0 : cm.getBossRank("赞助余额", 2);
            var add = "\t\t\t\t   #r#e< 余额商城 >#b \r\n\r\n#L10##b赞助码兑余额#l  #L11##d友情赞助#l  #L17##r累计赞助奖励#l   " + rn;

			 add += "当前余额:#b" + 赞助余额 + "#l" + rn;
			
            add += "#L0##r余额兑换#k#b点券#l #L1##r余额兑换#k#b金币#l #L2##r余额兑换#k#b道具#l" + rn;
            add += "#L3##r余额兑换#k#b装备#l #L4##r余额兑换#k#b时装#l #L13##r余额兑换#k#b消耗#l" + rn;
            add += "#L14##r余额兑换#k#b设置#l #L16##r余额兑换#k#b吸宠#l #L5##r余额兑换#k#b技能#l" + rn;
            add += "#L8##r余额自由#k#b转职#l #L6##r余额兑换#k#b会员#l #L7##r余额兑换#k#b超会#l" + rn;
          //  add += "";


  
			// add += "#L15##r使用余额兑换#k#b破攻#l" + rn;
            cm.sendSimple(add);
        } else if (status === 1) {
            selType = selection;
            var txt = "请选择下列你要兑换的内容：" + rn;
            switch (selection) {
                case 0:
                    txt = "当前余额兑换比例为：1余额=1000点券" + rn;
                    txt += "请输入你要兑换多少#b点券#l：\r\n";
                    break;
                case 1:
                    txt = "当前余额兑换比例为：1余额=1000#b万#l金币" + rn;
                    txt += "请输入你要兑换多少万#b金币#l：\r\n";
                    break;
                case 2:
                    selArr = itemArr;
                    break;
                case 3:
                    selArr = equipArr;
                    break;
                case 4:
                    selArr = cashArr;
                    break;
                case 13:
                    selArr = ConsumArr;
                    break;
                case 14:
                    selArr = SettingsArr;
                    break;
                case 15:
                    txt = "当前余额兑换比例为：1余额=#b10000破攻值#l" + rn;
                    txt += "请输入你要兑换多少#b破攻值#l：\r\n";
                    break;
                case 16:
                    cm.dispose();
                    cm.openNpc(9900004, "宠吸兑换");
                    return;
                case 5:
                    cm.dispose();
                    cm.openNpc(9900004, "技能兑换");
                    return;
                case 6:
                    cm.dispose();
                    if (赞助余额 >= 188 && !cm.haveItem(5010143, 1)) {
                        cm.setBossRankCount("赞助余额", -188);
                        cm.gainGachaponItemTime(5010143, 1, "月卡会员", 120);
                        cm.sendOk("#e#b[提示]：\r\n兑换成功季卡~\r\n");
                        return;
                    } else {
                        cm.dispose();
                        cm.sendOk("#e#r[提示]：\r\n余额不足188，或季卡会员未过期~\r\n");
                        return;
                    }

                case 7:
                    cm.dispose();
                    if (赞助余额 >= 888 && !cm.haveItem(5010152, 1)) {
                        cm.setBossRankCount("赞助余额", -888);
                        cm.gainGachaponItemTime(5010152, 1, "季卡会员", 120);
                        cm.sendOk("#e#b[提示]：\r\n兑换成功季卡~\r\n");
                        return;
                    } else {
                        cm.dispose();
                        cm.sendOk("#e#r[提示]：\r\n余额不足888，或季卡超会未过期~\r\n");
                        return;
                    }
                case 8:
                    cm.dispose();
                    cm.openNpc(9900004, "自由转职");
                    return;
                case 10:
                    cm.dispose();
                    cm.openNpc(9900004, "赞助余额");
                    return;
                case 11:
                    cm.dispose();
                    cm.打开网页("https://ka.b8ka.com/links/BC8DC3F5");
                    cm.sendOk("#e#r[提示如果浏览器未打请手动输入]：\r\nhttps://ka.b8ka.com/links/BC8DC3F5");
                    break;
                case 12:
                    if (cm.haveItem(5010152,1)) {
                    cm.warp(209000000);	
                    cm.dispose();					
	              } else {
	            	cm.sendOk("#b请确认是否有#r月卡#b或#r周卡#b！\r\n如需购买？购买位置，拍卖-余额商场-最下面~！！");
	              }
                    return;
                case 17:
                    cm.dispose();
                    cm.openNpc(9900004, "技能赞助礼品");
                    return;
                default:
                    cm.dispose();
            }
            if (selection < 2 || selection == 15) {
                cm.sendGetText(txt);
            } else {
                for (var i = 0; i < selArr.length; i++) {
                    txt += "\t#L" + i + "##d使用【" + selArr[i][0] + "】余额兑换#v" + selArr[i][1] + "##z" + selArr[i][1] + "# X " + selArr[i][2] + "#l\r\n";
                }
                cm.sendSimple(txt);
            }
        } else if (status == 2) {
            var txt2 = "";
            selitem = selection;
            if (selType == 0) {
                nxnum = cm.getText();
                if (nxnum % 1000 == 0 && (赞助余额 * 1000) >= nxnum&&nxnum>0) {
                    txt2 = "确定兑换" + nxnum + "点券吗？";
                } else {
                    cm.sendOk("余额不足，或点券不是整倍数！");
                    cm.dispose();
                    return;
                }

            } else if (selType == 1) {
                goldnum = cm.getText();
                if (goldnum % 1000 == 0 && (赞助余额 * 1000) >= goldnum&&goldnum>0) {
                    txt2 = "确定兑换" + goldnum + "万金币吗？";
                } else {
                    cm.sendOk("余额不足，或金币不是整倍数！");
                    cm.dispose();
                    return;
                }
            } else if (selType == 15) {
                pgldnum = cm.getText();
                if (pgldnum % 100 == 0 && (赞助余额 * 10000) >= pgldnum&&pgldnum>0) {
                    txt2 = "确定兑换" + pgldnum + "点破攻吗？";
                } else {
                    cm.sendOk("余额不足，或破攻值不是整倍数！");
                    cm.dispose();
                    return;
                }
            }
            else {
                if (赞助余额 >= selArr[selection][0]) {
                    txt2 = "#d确定使用【" + selArr[selection][0] + "】余额兑换#v" + selArr[selection][1] + "##z" + selArr[selection][1] + "# X " + selArr[selection][2] + " 个吗？#l";
                } else {
                    cm.sendOk("余额不足！");
                    cm.dispose();
                    return;
                }
            }
            cm.sendYesNo(txt2);
        } else if (status == 3) {
            if (selType == 0) {
                cm.setBossRankCount("赞助余额", -(nxnum / 1000));
                cm.gainNX(nxnum);
            } else if (selType == 1) {
                cm.setBossRankCount("赞助余额", -(goldnum / 1000));
                cm.gainMeso(goldnum * 10000);
            } else if (selType == 15) {
                cm.setBossRankCount("赞助余额", -(pgldnum / 10000));
                cm.getPlayer().addAccountExtraDamage(cm.getPlayer(), pgldnum);
            } else {
                cm.setBossRankCount("赞助余额", -selArr[selitem][0]);
                cm.gainItem(selArr[selitem][1], selArr[selitem][2]);
            }
            cm.itemArr;
			cm.sendOk("兑换成功！");
	
status=-1
            //cm.dispose();
        }
    }
}